package com.tjise.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tjise.commonutils.R;
import com.tjise.eduservice.entity.EduCourse;
import com.tjise.eduservice.entity.EduTeacher;
import com.tjise.eduservice.service.EduCourseService;
import com.tjise.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherfront")
@Slf4j
@Api(description = "讲师分页查询")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;

    //1 分页查询讲师的方法
    @ApiOperation("分页查询讲师的方法")
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page, @PathVariable long limit){
        log.info("前台传递过来的参数为--------"+ page + limit);

        Page<EduTeacher> pageTeacher = new Page<>(page,limit);
        Map<String,Object> map = teacherService.getTeacherFrontList(pageTeacher);
        //返回分页所有数据
        log.info("getTeacherFrontList()返回的数据为"+map);
        return R.ok().data(map);
    }
    /**
     * 根据id查询讲师详情功能
     */
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public  R getTeacherFrontInfo(@PathVariable("teacherId")String teacherId) {

        // 根据讲师id查询讲师的基本信息
        EduTeacher eduTeacher = teacherService.getById(teacherId);
        // 根据讲师id查询所讲课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);
        return R.ok().data("teacher",eduTeacher).data("courseList",courseList);
    }

}
